/*!
\copyright  Copyright (c) 2024 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      LE Audio Broadcast Self-Scan handover interface implementation.
*/

/*
    The broadcast manager on each peer acts more less independently when
    syncing to a broadcast. At any given time the contents of the local BASS
    servers will be equivalent, except for the transient synchronisation state.

    Because of the above there is no requirement to marshall any BASS related
    data for a handover.

    A handover may need to be vetoed if the local broadcast manager is in the
    process of doing something that is connection related.

    For example:

    * PAST requires a connection between a remote device that is already synced
      to a PA train and the local device. Changing the local address would
      break this connection, probably causing the PAST attempt to fail.
      Instead, veto until the PAST attempt succeeds or fails due to timeout.
*/

#if defined(INCLUDE_LE_AUDIO_BROADCAST)

#include "domain_marshal_types.h"
#include "app_handover_if.h"
#include "le_broadcast_manager_source.h"
#include "mirror_profile.h"

#include <logging.h>
#include <rtime.h>
#include <stdlib.h>


/*! \brief Do veto check during handovers.

    Reasons for broadcast manager to veto:
    * If it is currently waiting for PAST to complete.
      * PAST depends on a link between devices so changing the address of this device would interrupt it.

    \return TRUE to veto handover, FALSE otherwise.
*/
static bool leBroadcastManager_Veto(void)
{
    bool veto = FALSE;

    switch (leBroadcastManager_GetSyncState())
    {
    case broadcast_manager_sync_waiting_for_sync_to_pa:
        veto = TRUE;
        break;

    default:
        break;
    }

    DEBUG_LOG("leBroadcastManager_Veto veto %d is_primary %d",
              veto, MirrorProfile_IsRolePrimary());

    return veto;
}

/*! \brief Commit to the given role when a handover is comitted.
*/
static void leBroadcastManager_Commit(bool is_primary)
{
    UNUSED(is_primary);
}

REGISTER_HANDOVER_INTERFACE_NO_MARSHALLING(LE_BROADAST_MANAGER,
                                           leBroadcastManager_Veto,
                                           leBroadcastManager_Commit);


#endif /* INCLUDE_LE_AUDIO_BROADCAST */


